
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        药品添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <script type="text/javascript" src="lib/loading/okLoading.js"></script>
    <style>
        .imgs{display: none;}
        .picture{display: none;}
    </style>

</head>
<body>

<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <input type="hidden" name="id" value="">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <!--<form class="layui-form layui-form-pane" action="" id="add">-->
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>药品名称
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="med_Name" autocomplete="off" placeholder="输入药品名称"
                                   class="layui-input" lay-verify="required" lay-reqtext="药品名称是必填项，岂能为空？" value="">
                        </div>
                    </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'>*</span>药品库存
                    </label>
                    <div class="layui-input-block">
                        <input type="text" name="med_Inventory" autocomplete="off" placeholder="请输入药品库存"
                               class="layui-input" lay-verify="required" lay-reqtext="药品库存是必填项，岂能为空？" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'>*</span>价格
                    </label>
                    <div class="layui-input-block">
                        <input type="text" name="price" autocomplete="off" placeholder="请输入药品价格"
                               class="layui-input" lay-verify="required" lay-reqtext="药品价格是必填项，岂能为空？" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="add" lay-submit="">
                        保存
                    </button>
                </div>
                <!--</form>-->
                <div style="height:100px;"></div>
            </div>
        </div>



    </form>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>

<script>
    layui.use(['laydate','element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        okLoading.close($);
        form.render();


        //监听提交
        form.on('submit(add)', function(data){
            var med_Name=$("input[name='med_Name']").val();
            var med_Inventory=$("input[name='med_Inventory']").val();
            var price=$("input[name='price']").val();
            if(med_Name ===""){
                layer.msg('药品名称不能为空',{icon:5,time:2000});return false;
            }if(med_Inventory ===""){
                layer.msg('药品库存不能为空',{icon:5,time:2000});return false;
            }if(price ===""){
                layer.msg('药品价格不能为空',{icon:5,time:2000});return false;
            }
            var form=data.field;
            $.ajax({
                async:false,
                type:"post",
                url:"/medicine/add",
                data:form,
                error: function (){
                    alert("添加错误")
                },
                success:function(res)
                {
                    if(res.state === 200) {
                        alert("添加成功，请刷新页面")
                    }
                }
            });
            this.load("/index.html")
        });


        $(function () {
            communidy();
        });

    })
</script>
<!--栏目缩略图上传-->
<script>
    function upload(obj,id){
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        formData.append('id', id);//将id追加再id中
        //console.log(formData);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type:"post",
            processData: false,
            contentType: false,
            url:"xxx",
            data:formData,
            success:function(data){
                if(data.status == 1){
                    console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src',data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                }else{
                    layer.msg(data.info,{icon:2,time:1000});
                }
            }
        });
    }
</script>

</body>
</html>